// 用户接口
export interface User {
  id: number
  username: string
  name: string
  nickname: string
  thumb: string
  sex: number
  mobile: string
  phone: string
  email: string
  did: number
  department_ids: string
  position_id: number
  type: number
  status: number
  entry_time: string
  reg_pwd: string
  salt: string
  pwd: string
  last_login_time: string
  last_login_ip: string
  create_time: number
  update_time: number
  // 扩展字段
  department?: string
  position?: string
  departments?: string
  pname?: string
  department_names?: string
}

// 验证码接口
export interface Captcha {
  id: string
  image: string // Base64 encoded image
}

// 部门接口
export interface Department {
  id: number
  pid: number
  title: string
  leader_ids: string
  sort: number
  remark: string
  status: number
  create_time: number
  update_time: number
  // 扩展字段
  leader?: string
  children?: Department[]
}

// 岗位接口
export interface Position {
  id: number
  title: string
  remark: string
  status: number
  create_time: number
  update_time: number
  // 扩展字段
  groupName?: string
  group_id?: number[]
}

// API响应接口
export interface UserApiResponse<T> {
  code: number
  msg: string
  data: T
  count?: number
}

// 分页API响应接口
export interface UserPaginationResponse<T> {
  code: number
  msg: string
  data: {
    list: T[]
    total: number
    page?: number
    limit?: number
  }
}

// 用户信息接口
export interface UserInfo {
  id: number
  username: string
  nickname: string
  avatar: string
  create_time?: string
}

// 用户状态接口
export interface UserState {
  users: User[]
  userTotal: number
  departments: Department[]
  positions: Position[]
  positionTotal: number
  userInfo: UserInfo
  token: string | null
  isLogin: boolean
  captcha: Captcha | null
}

// 用户Store接口
// 注意：这个接口定义与shims-modules.d.ts中的useUserStore类型定义冲突
// 我们将其重命名为UserStoreInterface以避免冲突
interface UserStoreInterface extends UserState {
  // 用户列表相关
  getUserListAction: (params: any) => Promise<any>
  saveUserAction: (data: any) => Promise<any>
  setUserStatusAction: (data: any) => Promise<any>
  resetUserPasswordAction: (data: any) => Promise<any>
  changePasswordAction: (data: { old_password: string; new_password: string }) => Promise<any>

  // 部门相关
  getDepartmentOptionsAction: (params?: any) => Promise<any>
  getDepartmentListAction: () => Promise<any>
  saveDepartmentAction: (data: any) => Promise<any>
  deleteDepartmentAction: (id: number) => Promise<any>

  // 岗位相关
  getPositionOptionsAction: () => Promise<any>
  getPositionListAction: (params: any) => Promise<any>
  savePositionAction: (data: any) => Promise<any>
  deletePositionAction: (data: any) => Promise<any>

  // 登录相关
  loginAction: (data: {
    username: string
    password: string
    captcha: string
    captcha_token?: string
    captchaId?: string
  }) => Promise<any>
  getCaptchaAction: () => Promise<any>
  verifyCaptchaAction: (captchaId: string, captchaCode: string) => Promise<boolean>
  setToken: (token: string) => void
  setUserInfo: (info: User) => void
  getUserInfo: () => Promise<any>
  getUserInfoAction: () => Promise<any>
  validateTokenAction: () => Promise<boolean>
  resetUserInfoRequestState: () => void
  logoutAction: () => Promise<void>
}

// 用户列表参数接口
export interface UserListParams {
  page: number
  limit: number
  keywords?: string
  status?: string
  type?: string
  did?: string | number
}

// 导出UserStoreInterface接口，避免与store中的useUserStore冲突
export type { UserStoreInterface }
